/**************************************************************
 * metainfo.h - metainfo of media file
 * Copyright (c) 2009  Qin Xiaoxue  <crs.chin@gmail.com>
 *
 * This file is  free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
**************************************************************/


#ifndef __META_INFO_H
#define  __META_INFO_H

#include <stdio.h>
#include <glib.h>

/* if failed to convert some info str, it will be discarded, NULL
   returned */
#define FORCE_ICONVERT

struct meta{
  const gchar *artist;
  const gchar *title;
  const gchar *album;
  const gchar *year;
  const gchar *track;
  const gchar *genre;
  const gchar *comment;

  const gchar *internal_encoding;
  const gchar *lang;
  gboolean     sync;
  gboolean     iserr;
  const gchar *errstr;
  void *data;
};

struct media_format{
  const gchar *const fmt;

  gboolean (*probe)(FILE *fp);
  gboolean (*read)(FILE *fp, struct meta *meta);
  gboolean (*write)(FILE *fp, struct meta *meta);
  gchar   *(*get_property)(struct meta *meta, const gchar *property);
  gboolean (*set_property)(struct meta *meta, const gchar *property, const gchar *value);
  gboolean (*release)(struct meta *meta);
};

struct __metainfo;

typedef struct __metainfo metainfo_t;


/* flags for @get_metainfo */
#define METAINFO_WRITEBACK 1
#define METAINFO_KEEPENCODING 1<<1 /* keep media file meta info encodings when writeback */

/*
 *@url: path to the local audio file, weburl file:// is also supported
 *@encoding: all meta info will use @encoding encoded
 *
 *NOTE: currently encoding convert is only performed in zh environment
 *between incompatible encodings, like GB and utf8
 *
 *WARNNING: this function don't check if the @encoding is a valid
 *encoding, a invalid encoding will result all FALSE return in the
 *following function call, thsi also apply to encoding related
 *functions.
 */
metainfo_t *metainfo_get_metainfo(const gchar *url, const gchar *encoding, gint flag);

/*
 *NOTE: all returned const values must NOT be changed, all others
 *should be freed, currently only the value returned by @get_property
 *is changable and should be freed.
 */
const gchar *metainfo_get_artist(metainfo_t *mi);
const gchar *metainfo_get_title(metainfo_t *mi);
const gchar *metainfo_get_album(metainfo_t *mi);
const gchar *metainfo_get_year(metainfo_t *mi);
const gchar *metainfo_get_track(metainfo_t *mi);
const gchar *metainfo_get_genre(metainfo_t *mi);
const gchar *metainfo_get_comment(metainfo_t *mi);

gchar *metainfo_get_property(metainfo_t *mi, const gchar *property);

const gchar *metainfo_get_format(metainfo_t *mi);
const gchar *metainfo_get_path(metainfo_t *mi);
const gchar *metainfo_get_encoding(metainfo_t *mi);

gboolean metainfo_set_artist(metainfo_t *mi, const gchar *artist);
gboolean metainfo_set_title(metainfo_t *mi, const gchar *title);
gboolean metainfo_set_album(metainfo_t *mi, const gchar *album);
gboolean metainfo_set_year(metainfo_t *mi, const gchar *year);
gboolean metainfo_set_track(metainfo_t *mi, const gchar *track);
gboolean metainfo_set_genre(metainfo_t *mi, const gchar *genre);
gboolean metainfo_set_comment(metainfo_t *mi, const gchar *comment);
gboolean metainfo_set_property(metainfo_t *mi, const gchar *property, const gchar *value);

gboolean metainfo_set_encoding(metainfo_t *mi, const gchar *encoding);

void         metainfo_clearerr_metainfo(metainfo_t *mi);
const gchar *metainfo_strerr_metainfo(metainfo_t *mi);

/* write to the default is @path is NULL */
gboolean metainfo_write_metainfo(metainfo_t *mi, const gchar *path);

void metainfo_put_metainfo(metainfo_t *mi);

/* supported metainfo media types */
#include "metainfo_mp3.h"

#endif	/*  __META_INFO_H */
